<?php
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
cfc('core')->checklogin();
$this->checkmanage();
if($_RQ['op']=='list'){
	
	$bid=pdo_getcolumn('jy_smallquan_manager',array('mid'=>$_SESSION['uid']),'bid');
	$building=pdo_get('jy_smallquan_building',array('id'=>$bid));
	$return['title']=$building['area'].$building['qishu'].$building['dongshu'].'栋';
	$pindex = max(1, intval($_RQ['page']));
	$psize = 15;
	
	$params=array('uniacid'=>$_SESSION['uniacid'],'status'=>0);	
    //$fields=array('id','ordersn','name','mobile','driver_id','mid','createtime','status','price','price1','start_seat','dest_seat','cuid');
    $orderby='createtime desc';
	$total='';
	$return['list']=pdo_getslice('jy_smallquan_manager_order',$params,array($pindex,$psize),$total,$fields,'',$orderby);	
	
	if($return['list']){
		foreach($return['list'] as &$v){
			$member=pdo_get('core_members',array('id'=>$v['mid']),array('mobile','realname'));
			$v['realname']=$member['realname'];
			$v['mobile']=$member['mobile'];
			$v['images']=json_decode($v['images'],true);
			//$v['createtime']=date('Y-m-d H:i:s',$v['createtime']);
			$hid=pdo_getcolumn('jy_smallquan_household',array('mid'=>$v['mid']),'hid');
			$h=pdo_get('jy_smallquan_house',array('id'=>$hid));
			$v['address']=$h['dongshu'].'栋'.$h['danyuan'].'单元'.$h['room_num'].'室';
		}
	}
	$return['type']=array('1'=>'拍照','2'=>'送水','3'=>'维修','4'=>'帮忙');
	$return['status']=array('0'=>'待服务','1'=>'正在处理','2'=>'已完成');
	exi($return);
}
if($_RQ['op']=='done'){
	$id=$_RQ['id'];
	if(!$id){
		exi('参数错误','error');
	}
	$o=pdo_get('jy_smallquan_manager_order',array('id'=>$id));
	if($o['status']){
		exi('任务状态错误，请刷新再试','error');
	}
	$member=pdo_get('core_members',array('id'=>$v['mid']),array('mobile','realname'));
	pdo_update('jy_smallquan_manager_order',array('managerid'=>$_SESSION['uid'],'status'=>1),array('id'=>$id));
	exi('已接受','','/manageorder/');
}
	